﻿<UserControl x:Class="Modules.DatabaseSettings.Views.AdvancedSettingsView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:commands="clr-namespace:Microsoft.Practices.Composite.Presentation.Commands;assembly=Microsoft.Practices.Composite.Presentation"
             xmlns:commonCommands="clr-namespace:Common.Commands;assembly=Common.Commands"
             xmlns:controls="clr-namespace:Common.Controls.Controls;assembly=Common.Controls"
             xmlns:dialogs="clr-namespace:Common.Dialogs;assembly=Common.Dialogs"
             xmlns:commonConverters="clr-namespace:Common.Dialogs.Converters;assembly=Common.Dialogs"
             mc:Ignorable="d" x:Name="dbSettingsView"
             d:DesignHeight="300" d:DesignWidth="500">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Common.Dialogs;component/Styles/CommonStyles.xaml"/>
            </ResourceDictionary.MergedDictionaries>

            <commonConverters:EmptyStringToVisibilityConverter x:Key="EmptyStringToVisibilityConverter"/>
            <commonConverters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter"/>
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid>
        <GroupBox Grid.Row="1" Header="Database schema settings" Margin="4">

            <StackPanel Margin="4,10,4,4">
                <Expander x:Name="PsqlLocatorExpander" Header="Psql search"
                          IsExpanded="{Binding PsqlLocatorDetailsVisible,Mode=TwoWay}" 
                          Grid.Row="0" Grid.ColumnSpan="2">
                    <Expander.HeaderTemplate>
                        <DataTemplate>
                            <Grid Width="200">
                            <!--<Grid Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Expander}},Path=ActualWidth}">-->
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="Auto"/>
                                            <ColumnDefinition Width="*"/>
                                        </Grid.ColumnDefinitions>
                                        <TextBlock Text="Psql path" FontWeight="Bold" Grid.Column="0"/>
                                    <TextBox Margin="42,0,26,0" Grid.Column="1"
                                                 Text="{Binding ElementName=PsqlLocatorExpander, Path=DataContext.DatabaseDeployInfo.PsqlPath,Mode=TwoWay,ValidatesOnExceptions=True}"
                                                 IsReadOnly="True"/>
                                    </Grid>
                            </Grid>
                        </DataTemplate>
                    </Expander.HeaderTemplate>
                    <Grid x:Name="PsqlLocatorLayout" Grid.Row="1" Grid.ColumnSpan="2" Margin="24,4,2,4"
                      Visibility="{Binding IsPsqlLocatorVisible,Converter={StaticResource BoolToVisibilityConverter}}">
                        <Grid.RowDefinitions>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="120"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <TextBlock Text="Status:" Grid.Row="0" Grid.Column="0"/>
                        <TextBlock Text="{Binding PsqlLocator.SearchStatus}" Grid.Row="0" Grid.Column="1"/>
                        <TextBlock Text="Progress:" Grid.Row="1" Grid.Column="0"/>
                        <StackPanel Orientation="Horizontal" Grid.Row="1" Grid.Column="1">
                            <TextBlock Text="{Binding PsqlLocator.ScannedDirs}" />
                            <TextBlock Text=" of " />
                            <TextBlock Text="{Binding PsqlLocator.TotalDirs}" />
                        </StackPanel>
                        <TextBlock Text="Search pattern:" Grid.Row="2" Grid.Column="0"/>
                        <TextBlock Text="{Binding PsqlLocator.SearchPattern}" Grid.Row="2" Grid.Column="1"/>
                        <TextBlock Text="Initial search path:" Grid.Row="3" Grid.Column="0"/>
                        <TextBlock Text="{Binding PsqlLocator.InitialPath}" Grid.Row="3" Grid.Column="1"/>
                        <TextBlock Text="Current path:" Grid.Row="4" Grid.Column="0"/>
                        <TextBlock Text="{Binding PsqlLocator.CurrentPath}" Grid.Row="4" Grid.Column="1"/>
                        <StackPanel Orientation="Horizontal" Grid.Row="5" Grid.ColumnSpan="2">
                            <Button Content="Start" Style="{StaticResource DialogButtonStyle}" Width="90" Margin="0,6,6,6"
                                commands:Click.Command="{Binding LocatePsqlCommand}"
                                ToolTip="Start location of psql executable"/>
                            <Button Content="Stop" Style="{StaticResource DialogButtonStyle}" Width="90" Margin="6"
                                commands:Click.Command="{Binding CancelLocatePsqlCommand}"
                                ToolTip="Stop location of psql executable"/>
                            <Button Content="Set initial path" Style="{StaticResource DialogButtonStyle}" Width="90" Margin="6"
                                commands:Click.Command="{Binding SetPsqlSearchPathCommand}"
                                ToolTip="Set initial search path for psql executable"/>
                        </StackPanel>
                    </Grid>
                </Expander>
                <Grid x:Name="DbSchemaLayout" Margin="0,-2,0,0" >
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="120"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>

                    <TextBlock Grid.Row="2" Grid.Column="0" VerticalAlignment="Center" Text="Admin login" FontWeight="Bold"/>
                    <TextBox Grid.Row="2" Grid.Column="1" Text="{Binding DatabaseDeployInfo.AdminLogin,Mode=TwoWay,ValidatesOnExceptions=True}" Grid.ColumnSpan="2"/>

                    <TextBlock Grid.Row="3" Grid.Column="0" VerticalAlignment="Center" Text="Admin password" FontWeight="Bold"/>
                    <TextBox Grid.Row="3" Grid.Column="1" Text="{Binding DatabaseDeployInfo.AdminPassword,Mode=TwoWay,ValidatesOnExceptions=True}" Grid.ColumnSpan="2"/>

                    <Separator Grid.Row="4" Grid.ColumnSpan="2" Margin="0,16,0,16"/>

                    <TextBlock Grid.Row="5" Grid.Column="0" VerticalAlignment="Center" Text="Database" FontWeight="Bold"/>
                    <TextBox Grid.Row="5" Grid.Column="1" Text="{Binding DatabaseDeployInfo.DatabaseName,Mode=TwoWay,ValidatesOnExceptions=True}" Grid.ColumnSpan="2"/>

                    <TextBlock Grid.Row="6" Grid.Column="0" VerticalAlignment="Center" Text="User" FontWeight="Bold"/>
                    <TextBox Grid.Row="6" Grid.Column="1" Text="{Binding DatabaseDeployInfo.UserName,Mode=TwoWay,ValidatesOnExceptions=True}" Grid.ColumnSpan="2"/>

                    <TextBlock Grid.Row="7" Grid.Column="0" VerticalAlignment="Center" Text="Password" FontWeight="Bold"/>
                    <TextBox Grid.Row="7" Grid.Column="1" Text="{Binding DatabaseDeployInfo.Password,Mode=TwoWay,ValidatesOnExceptions=True}" Grid.ColumnSpan="2"/>

                    <StackPanel Grid.Row="8" Grid.ColumnSpan="2" Orientation="Horizontal" HorizontalAlignment="Right">
                        <Button Content="Basic settings" Style="{StaticResource DialogButtonStyle}" Width="120" Margin="6"
                                commands:Click.Command="{Binding BasicSettingsCommand}"
                                ToolTip="Show advanced database configuration"/>
                        <Button Content="Vaildate schema" Width="120" Margin="6"
                                Style="{StaticResource DialogButtonStyle}" 
                                commands:Click.Command="{Binding ValidateSchemaCommand}"
                                commands:Click.CommandParameter="{Binding ElementName=dbSettingsView}"
                                ToolTip="Validates schema against existing database"/>
                        <Button Content="Deploy schema" Width="120" Margin="6"
                                Style="{StaticResource DialogButtonStyle}" 
                                commands:Click.Command="{Binding DeploySchemaCommand}"
                                ToolTip="Recreates database, deploys schema, user and permissions"/>
                    </StackPanel>
                </Grid>
            </StackPanel>
        </GroupBox>
    </Grid>
</UserControl>
